from django.db import models


# Create your models here.


class Department(models.Model):
    name = models.CharField(max_length=20, verbose_name='姓名')

    class Meta:
        db_table = 'depar'


class User(models.Model):
    username = models.CharField(max_length=100, verbose_name='用户名')
    password = models.CharField(max_length=250, verbose_name='密码')
    authority = models.IntegerField(verbose_name='权限')
    depa = models.ForeignKey(Department, on_delete=models.CASCADE)

    # 1是超级权限,2是普通权限
    class Meta:
        db_table = 'user'


class Bcate(models.Model):
    name = models.CharField(max_length=20, verbose_name='分类名称')

    class Meta:
        db_table = 'bcate'
        verbose_name = '分类表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Book(models.Model):
    name = models.CharField(max_length=50, verbose_name='图书')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    cate = models.ForeignKey(Bcate, on_delete=models.CASCADE, verbose_name='分类ID')

    class Meta:
        db_table = 'book'
        verbose_name = '图书表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class RedisUser(models.Model):
    username = models.CharField(max_length=100, verbose_name='用户名')
    password = models.CharField(max_length=255, verbose_name='密码')
    mobile = models.CharField(max_length=11, verbose_name='手机号')

    class Meta:
        db_table = 'ruser'

    def __str__(self):
        return self.username
